package com.google.gwt.livinglife.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class LoginInfoFactory {
	private static LoginInfo login_info;
	/**
	 * If we have a login info available to us, don't refresh it.
	 * Just provide the stale copy.
	 */
	public static LoginInfo getLoginInfoLazy() {
		if (login_info == null) {
			refreshLoginInfo();
		}
		return login_info;
	}
	/**
	 * Always make a fresh rpc to get the login info.
	 */
	public static LoginInfo getLoginInfo() {
		refreshLoginInfo();
		return login_info;
	}
	private static void refreshLoginInfo() {
    LoginServiceAsync loginService = GWT.create(LoginService.class);
    loginService.login(GWT.getHostPageBaseURL(),
                    new AsyncCallback<LoginInfo>() {
            public void onFailure(Throwable error) {
            	
            }
            public void onSuccess(LoginInfo result) {
                    login_info = result;
            }
    });
	}
}
